package com.shenmazong.map;

/**
 * @program: server-java-demo
 * @description: HashMapApplication
 * @author: 亮子说编程
 * @create: 2020-10-16 20:35
 **/
public class HashMapApplication {

    static final int MAXIMUM_CAPACITY = 1 << 30;

    static final int tableSizeFor(int cap) {
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
    }

    public static void main(String[] args) {
        System.out.println("10=" + tableSizeFor(10));
        System.out.println("17=" + tableSizeFor(17));
        System.out.println("33=" + tableSizeFor(33));
    }
}
